﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CCF20Model;
using System.Windows;
using System.Collections;
using WiseLink.RDS.Resource;

namespace CCF20.CustomerState
{
    public interface ICustomerHandler
    {
        Vehicle CurrentVehicle { get; set; }
        ICustomerState CurrentState { get; set; }
        void InitializeState();
    }
    public class CustomerHandler : ICustomerHandler
    {
        public Vehicle CurrentVehicle { get; set; }
        public ICustomerState CurrentState { get; set; }
        protected VehicleModel vehicleModel { get; set; }
        
        public CustomerHandler(VehicleModel model, Vehicle vehicle)
        {
            CurrentVehicle = vehicle;
            vehicleModel = model;
            InitializeState();
        }
        public void InitializeState()
        {
            if (CurrentVehicle.LastContactResult.Contains(WiseLinkRDSStatus.Contact_WillRepair))
            {
                setState(new CustomerWillRepair(CurrentVehicle,vehicleModel));
            }
            else if (CurrentVehicle.LastContactResult.Contains(WiseLinkRDSStatus.Contact_Reject))
            {
                setState(new CustomerReject(CurrentVehicle, vehicleModel));
            }
            else if (CurrentVehicle.LastContactResult.Contains(WiseLinkRDSStatus.Contact_Giveup))
            {
                setState(new CustomerGiveup(CurrentVehicle, vehicleModel));
            }
            else if (CurrentVehicle.LastContactResult.Contains(WiseLinkRDSStatus.Contact_NotContactYet))
            {
                setState(new CustomerNoContact(CurrentVehicle, vehicleModel));
            }
            else
            {
                setState(new CustomerNoContact(CurrentVehicle, vehicleModel));
                LoggerHelper.LogCCF20(string.Format("未知客户:{0}状态:{1}", CurrentVehicle.Devices.FirstOrDefault().IDCSimNumber, CurrentVehicle.LastContactResult));

            }

        }
        private void ShowMessageToCustomer(string msg)
        {
            if (!string.IsNullOrEmpty(msg))
            {
                Utility.ShowMessageBox(msg);
            }
        }

        
        public void setState(ICustomerState customerState)
        {
            CurrentState = customerState;
            LoggerHelper.LogCCF20(string.Format("Set Customer State:{0} IDC:{1}", customerState.StateName, CurrentVehicle.Devices.FirstOrDefault().IDCSimNumber));
        }
    }
}
